package com.zjw.service.message.impl;

import com.zjw.service.message.IConnectSession;
import com.zjw.service.message.IUserPool;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SimpleUserPool implements IUserPool {

    private final Map<Long, IConnectSession> pool = new ConcurrentHashMap<>();

    @Override
    public void connect(long uid, IConnectSession session) {
        IConnectSession old = pool.put(uid, session);
        if (old != null) {
            old.disconnect();
        }
    }

    @Override
    public void disconnect(long uid) {
        IConnectSession remove = pool.remove(uid);
    }

    @Override
    public IConnectSession getConnectSession(long uid) {
        return pool.get(uid);
    }

    @Override
    public int size() {
        return pool.size();
    }
}
